package top.kaoshanji.q1ch06e.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;

import java.util.logging.Logger;

/**
 * 代码清单-q1ch06e-133页b：将LoggingAspect切面作为第一个要执行的对象
 * @author kaoshanji
 * ^_^
 * create time 2025/4/29 11:21
 */
@Aspect
@Order(100)
public class LoggingAspect {

    private Logger logger = Logger.getLogger(LoggingAspect.class.getName());

    public void setLogger(Logger logger) {
        this.logger = logger;
    }

    @Around("@annotation(ToLog)")
    public Object log(ProceedingJoinPoint joinPoint) throws Throwable {
        logger.info("...日志切面拦截了目标方法的调用...");

        Object returnedValue = joinPoint.proceed();

        logger.info("...日志切面执行了目标方法调用之后的结果：" + returnedValue);

        return returnedValue;
    }

}
